/*
*	ID : Pallab
* 	PROG : 5907
* 	LANG : C++
* 	2012-11-30-07.45.15 Friday
*
* 	"I have not failed, I have just found 10000 ways that won't work.
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <numeric>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define foR(i1,st,ed) for(int i1 = st , j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i1,ed) foR( i1 , 0 , ed )
#define foE(i1,st,ed) foR( i1, st, ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

inline void wait(double seconds) {
    double endtime = clock() + (seconds * CLOCKS_PER_SEC);
    while (clock() < endtime) {
        ;
    }
}
template<class T>
inline T fastIn() {
    register char c=0;
    register T a=0;
    bool neg=false;
    while(c<33)c=getchar();
    while(c>33) {
        if(c=='-') {
            neg=true;
        } else {
            a= (a*10)+(c-'0');
        }
        c=getchar();
    }
    return neg?-a:a;
}
string cards="23456789TJQKA";
inline int get_card_value(char ch) {
    return cards.find(ch);
}
string suits="hdcs";
inline int get_suit_value(char ch) {
    return suits.find(ch);
}
inline int bc(int msk) {
    int c=0;
    for(c=0; msk ; ++c) {
        msk&= (msk-1);
    }
    return c;
}

int vi[15];
string ss[13];
inline void read() {
    fo(i,13) {
        cin>>ss[i];
        vi[i]=get_card_value(ss[i][0]);
    }
}
const int inf = 1023456789;
inline bool clean(int msk, int i) {
    return msk&(1<<i) ? false : true ;
}
inline int select(int msk, int i) {
    return msk|(1<<i);
}
int dp[1<<14];
int go(int m) {
    if( bc(m)>=13 )return 0;
    int &bst=dp[m];
    if(bst!=-1)return bst;
    bst=inf;
    for(int i=0; i<13; ++i) {
        if( clean(m,i) ) {
            int nm=select(m,i);
            int sz=1,v=vi[i];
            //-------------------------------------------------

            while(true) {
                bool change=false;
                for(int k=0; k<13; ++k) {
                    if(clean(nm,k) && v+1==vi[k]) {
                        ++sz,nm=select(nm,k),v=v+1;
                        change=true;
                        break;
                    }
                }
                if(sz>=5)bst=min(bst, 1+go(nm));
                if(!change)break;
            }
        }
    }

    //3 card of same value and two card of other vlaue
    for(int i=0; i<13; ++i) {
        if(!clean(m,i))continue;
        for(int j=i+1; j<13; ++j) {
            if(!clean(m,j))continue;
            if(vi[i]!=vi[j])continue;
            for(int k=j+1; k<13; ++k) {
                if(!clean(m,k))continue;
                if(vi[i]!=vi[k])continue;

                if(i==j||i==k||j==k)continue;
                int nm=m;
                nm=select(nm,i),nm=select(nm,j),nm=select(nm,k);

                for(int p=0; p<13; ++p) {
                    if(vi[i]==vi[p])continue;
                    if( !clean(nm,p))continue;
                    for(int q=p+1; q<13; ++q) {
                        if(!clean(nm,q))continue;
                        if(vi[p]!=vi[q])continue;
                        if(p==q)continue;
                        int nnm=nm;
                        nnm=select(nnm,p),nnm=select(nnm,q);
                        bst=min(bst,1+go(nnm));
                    }
                }

            }
        }
    }
    //four card of same value
    for(int i=0; i<13; ++i) {
        if(!clean(m,i))continue;
        for(int j=i+1; j<13; ++j) {
            if(!clean(m,j))continue;
            if(vi[i]!=vi[j])continue;

            for(int k=j+1; k<13; ++k) {
                if(!clean(m,k))continue;
                if(vi[i]!=vi[k])continue;

                for(int l=k+1; l<13; ++l) {
                    if(!clean(m,l))continue;
                    if(vi[i]!=vi[l])continue;

                    if(i==j||i==k||i==l||j==k||j==l||k==l)continue;
                    int nm=m;
                    nm=select(nm,i),nm=select(nm,j),nm=select(nm,k),nm=select(nm,l);
                    bst=min(bst,1+go(nm));
                }
            }
        }
    }

//three card of same value
    for(int i=0; i<13; ++i) {
        if(!clean(m,i))continue;
        for(int j=i+1; j<13; ++j) {
            if(!clean(m,j))continue;
            if(vi[i]!=vi[j])continue;
            for(int k=j+1; k<13; ++k) {
                if(!clean(m,k))continue;
                if(vi[i]!=vi[k])continue;

                if(i==j||i==k||j==k)continue;
                int nm=m;
                nm=select(nm,i),nm=select(nm,j),nm=select(nm,k);
                bst=min(bst,1+go(nm));

            }
        }
    }
    //two card of same value
    for(int i=0; i<13; ++i) {
        if(!clean(m,i))continue;
        for(int j=i+1; j<13; ++j) {
            if(i==j)continue;
            if(vi[i]!=vi[j])continue;
            if(!clean(m,j))continue;
            int nm=m;
            nm=select(nm,i),nm=select(nm,j);
            bst=min(bst,1+go(nm) );
        }
    }

    //single
    for(int i=0; i<13; ++i) {
        if( clean(m,i) )
            bst=min(bst,1+go(select(m,i)));
    }
    return bst;
}
//vector<string> vvs;
void bk(int m, int retval) {
    if( bc(m)>=13 )return ;

    //5 or more cards of increasing order
    for(int i=0; i<13; ++i) {
        if( clean(m,i) ) {
            int nm=select(m,i);
            int sz=1,v=vi[i];
            vector<string> vs;
            vs.pb(ss[i]);
            //-------------------------------------------------
            while(true) {
                bool change=false;
                for(int k=0; k<13; ++k) {
                    if(clean(nm,k) && v+1==vi[k]) {
                        ++sz,nm=select(nm,k),v=v+1,vs.pb(ss[k]);
                        change=true;
                        break;
                    }
                }
                if( sz>=5 ) {
                    int tmp=1+go(nm);
                    if(tmp==retval) {
                        fo(xi,SZ(vs)) {
                            if(xi)cout<<' ';
                            cout<<vs[xi];
                        }
                        line;
                        bk(nm,retval-1);
                        return ;
                    }
                }
                if(!change)break;
            }
        }
    }

    for(int i=0; i<13; ++i) {
        if(!clean(m,i))continue;
        for(int j=i+1; j<13; ++j) {
            if(!clean(m,j))continue;
            if(vi[i]!=vi[j])continue;
            for(int k=j+1; k<13; ++k) {
                if(!clean(m,k))continue;
                if(vi[i]!=vi[k])continue;

                if(i==j||i==k||j==k)continue;
                int nm=m;
                nm=select(nm,i),nm=select(nm,j),nm=select(nm,k);

                for(int p=0; p<13; ++p) {
                    if(vi[i]==vi[p])continue;
                    if( !clean(nm,p))continue;
                    for(int q=p+1; q<13; ++q) {
                        if(!clean(nm,q))continue;
                        if(vi[p]!=vi[q])continue;
                        if(p==q)continue;
                        int nnm=nm;
                        nnm=select(nnm,p),nnm=select(nnm,q);
                        int tmp=1+go(nnm);
                        if(tmp==retval) {
                            //vvs.pb(ss[i]);vvs.pb(ss[j]);vvs.pb(ss[k]);vvs.pb(ss[p]);vvs.pb(ss[q]);
                            cout<<ss[i]<<' '<<ss[j]<<' '<<ss[k]<<' '<<ss[p]<<' '<<ss[q];
                            line;
                            bk(nnm,retval-1);
                            return ;
                        }
                    }
                }

            }
        }
    }

    for(int i=0; i<13; ++i) {
        if(!clean(m,i))continue;
        for(int j=i+1; j<13; ++j) {
            if(!clean(m,j))continue;
            if(vi[i]!=vi[j])continue;

            for(int k=j+1; k<13; ++k) {
                if(!clean(m,k))continue;
                if(vi[i]!=vi[k])continue;

                for(int l=k+1; l<13; ++l) {
                    if(!clean(m,l))continue;
                    if(vi[i]!=vi[l])continue;

                    if(i==j||i==k||i==l||j==k||j==l||k==l)continue;
                    int nm=m;
                    nm=select(nm,i),nm=select(nm,j),nm=select(nm,k),nm=select(nm,l);
                    int tmp=1+go(nm);
                    if(tmp==retval) {
                        //vvs.pb(ss[i]);vvs.pb(ss[j]);vvs.pb(ss[k]);vvs.pb(ss[l]);
                        cout<<ss[i]<<' '<<ss[j]<<' '<<ss[k]<<' '<<ss[l];
                        line;
                        bk(nm,retval-1);
                        return ;
                    }
                }
            }
        }
    }
    for(int i=0; i<13; ++i) {
        if(!clean(m,i))continue;
        for(int j=i+1; j<13; ++j) {
            if(!clean(m,j))continue;
            if(vi[i]!=vi[j])continue;
            for(int k=j+1; k<13; ++k) {
                if(!clean(m,k))continue;
                if(vi[i]!=vi[k])continue;

                if(i==j||i==k||j==k)continue;
                int nm=m;
                nm=select(nm,i),nm=select(nm,j),nm=select(nm,k);
                int tmp=1+go(nm);
                if(tmp==retval) {
                    //vvs.pb(ss[i]);vvs.pb(ss[j]);vvs.pb(ss[k]);
                    cout<<ss[i]<<' '<<ss[j]<<' '<<ss[k];
                    line;
                    bk(nm,retval-1);
                    return ;
                }
            }
        }
    }
    for(int i=0; i<13; ++i) {
        if(!clean(m,i))continue;
        for(int j=i+1; j<13; ++j) {
            if(i==j)continue;
            if(vi[i]!=vi[j])continue;
            if(!clean(m,j))continue;
            int nm=m;
            nm=select(nm,i),nm=select(nm,j);
            int tmp=1+go(nm) ;
            if(tmp==retval) {
                //vvs.pb(ss[i]);vvs.pb(ss[j]);
                cout<<ss[i]<<' '<<ss[j];
                line;
                bk(nm,retval-1);
                return ;
            }
        }
    }


    for(int i=0; i<13; ++i) {
        if( clean(m,i) ) {
            int tmp=1+go(select(m,i));
            if(tmp==retval) {
                //vvs.pb(ss[i]);
                cout<<ss[i];
                line;
                bk(select(m,i),retval-1);
                return ;
            }
        }
    }
}

inline void proc() {
    SET(dp,-1);
    int retval=go(0);
    cout<<retval;
    line;
    bk(0,retval);
}
int main() {
    int kase = 1;
#if defined( xerxes_pc )
    freopen("H.in", "rt", stdin);
    freopen("myH.out","wt",stdout);
#endif
    kase=fastIn<int>();
    fo(i,kase) {
        read();
        proc();
    }
    return 0;
}
